import { ItemData } from "../../../resource/info/ItemData";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { DisplayUtil } from "../../../../common/DisplayUtil";
import { ObjCreate } from "../ObjCreate";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
import { GameDefConfig } from "../../../resource/GameDefConfig";
import { ModelType } from "../../../scene/modle/data/ModelType";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { MagicWeaponUtil } from "../../magicWeapon/MagicWeaponUtil";
import { MagicWeaponConfig } from "../../../resource/MagicWeaponConfig";
import { MWPropertyItemData } from "../../magicWeapon/data/MWPropertyItemData";
import { Language } from "../../../../../extend/language/Language";
import { TAmuletConfig } from "../../../../../Message/Db/Tables/TAmuletConfig";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { TextAlign } from "../../../../../flashx/textLayout/formats/TextAlign";
import { FontUtil } from "../../../../common/font/FontUtil";
import { SWFPlayer } from "../../../scene/modle/SWFPlayer";
import { AutoLayoutTextContainer } from "../../../../common/text/AutoLayoutTextContainer";
import { ColorConfig } from "../../../resource/ColorConfig";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
type int = number;
//class MagicWeaponToolTip
    
    export  class MagicWeaponToolTip /* flash.display.Sprite */
    {
        constructor(arg1: ItemData=null)
        {
            
            this.initView();
            this.init(arg1);
            return;
        }

        /* internal  */setAllVisibles(arg1: Boolean): void
        {
            this._lbCheck1.visible = arg1;
            this._lbCheck2.visible = arg1;
            this._lbCheck3.visible = arg1;
            this._lbScore.visible = arg1;
            this._askContainer.visible = arg1;
            this._txtScore.visible = !arg1;
            this._score.visible = !arg1;
            this._propContainer.visible = !arg1;
            this._txtMaxLevel.visible = !arg1;
            this._txtMaxScore.visible = !arg1;
            this._txtAttack.visible = !arg1;
            this._faultTxt1.text = "";
            this._faultTxt2.text = "";
            return;
        }

        public set data(arg1: ItemData)
        {
            this.init(arg1);
            return;
        }

        public /* override */ get width(): number
        {
            return 200;
        }

        public set equiped(arg1: Boolean)
        {
            if (arg1) 
            {
                if (this._equippedBitmap == null) 
                {
                    this._equippedBitmap = GlobalClass.getBitmap(ImagesConst.Equipped);
                }
                this._equippedBitmap.x = 113;
                this._equippedBitmap.y = 0;
                this.addChildAt(this._equippedBitmap, 0);
            }
            else 
            {
                DisplayUtil.removeMe(this._equippedBitmap);
            }
            return;
        }

        public showUpArrow(arg1: Boolean, arg2: int): void
        {
            if (!arg1 || arg2 == 0) 
            {
                DisplayUtil.removeMe(this._bmpUpArrow);
                DisplayUtil.removeMe(this._txtUpValue);
                return;
            }
            if (this._bmpUpArrow == null) 
            {
                this._bmpUpArrow = ObjCreate.createBitmap(null, 0, 126, this);
            }
            if (this._txtUpValue == null) 
            {
                this._txtUpValue = this.createGTextField("", 0, 127, 100, 20, this);
            }
            this._txtUpValue.text = arg2.toString();
            if (arg2 >= 0) 
            {
                this._bmpUpArrow.bitmapData = GlobalClass.getBitmapData(ImagesConst.RangeRaise);
                this._txtUpValue.textColor = 65280;
            }
            else 
            {
                this._bmpUpArrow.bitmapData = GlobalClass.getBitmapData(ImagesConst.RangeDecline);
                this._txtUpValue.textColor = 16711680;
            }
            var loc1=this._txtAttack.text;
            var loc2=DisplayUtil.getStringPixes(loc1, 14);
            this._bmpUpArrow.x = this._txtAttack.x + loc2 + 13;
            this._txtUpValue.x = this._bmpUpArrow.x + 12;
            return;
        }

        /* internal  */init(arg1: ItemData): void
        {
            this._data = arg1;
            if (arg1 == null) 
            {
                if (this._icon) 
                {
                    this._icon.stop();
                }
                return;
            }
            this._txtName.htmlText = this._data.htmlName;
            var loc1=ItemsUtil.isBind(this._data) ? 1 : 0;
            if (!loc1) 
            {
                loc1 = this._data.bind;
            }
            var loc2=GameDefConfig.instance.getEBind(loc1);
            if (loc2) 
            {
                this._txtBind.htmlText = loc2.name;
            }
            this._icon.move(60, 100);
            this._icon.loadComplete = this.loadIconComplete;
            this._icon.load(this._data.effect + ".swf", ModelType.FabaoPlayer, null);
            this._lbGet.htmlText = this._data.itemInfo.item.descStr;
            if (arg1.isHasIdentify()) 
            {
                this.setIdentifyMode();
            }
            else 
            {
                this.setNotIdentifyMode();
            }
            return;
        }

        /* internal  */loadIconComplete(arg1): void
        {
            this._icon.move(60, 100);
            return;
        }

        /* internal  */setIdentifyMode(): void
        {
            var loc8=null;
            var loc9=null;
            var loc10=null;
            var loc11=null;
            this.setAllVisibles(false);
            this._lbAttack.textColor = 16743424;
            this._lbShouHu.textColor = 16743424;
            if (this._data.magicWeaponLv > 0) 
            {
                loc8 = HTMLUtil.addColor(" +" + this._data.magicWeaponLv.toString(), this._data.itemInfo.colorStr);
                this._txtName.htmlText = this._data.htmlName + loc8;
            }
            this.isNoPropertyWeapon = MagicWeaponUtil.isNoPropertyWeapon(this._data);
            this._txtScore.htmlText = "<font color=\'#FECD04\'>" + this._data.magicWeaponScore + "</font>";
            var loc1=MagicWeaponUtil.analyseProperty(this._data);
            var loc2=0;
            var loc3="";
            var loc4=MagicWeaponConfig.instance.getItemByTypeColorLevel(5, this._data.color, this._data.magicWeaponLv);
            var loc5=0;
            if (loc4 != null) 
            {
                loc5 = loc4.add;
            }
            this._txtAttack.htmlText = "";
            var loc6=0;
            while (!(loc1 == null) && loc6 < loc1.length) 
            {
                if (MagicWeaponUtil.isNoPropertyWeapon(this._data)) 
                {
                    break;
                }
                if ((loc9 = loc1[loc6] as MWPropertyItemData) != null) 
                {
                    loc10 = "<font color=\'#00ff00\'>+" + int(loc9.property * loc5 / 100) + "</font>";
                    if (loc5 == 0) 
                    {
                        loc10 = "";
                    }
                    if (loc9.typeName == MWPropertyItemData.TypeName_Main && loc9.property > 0) 
                    {
                        loc3 = "<font color=\'#FECD04\'>" + loc9.name + "  " + loc9.property + "</font>" + loc10;
                        this._txtAttack.htmlText = loc3;
                    }
                    else 
                    {
                        loc11 = "  ";
                        if (loc9.name.length >= 7) 
                        {
                            loc11 = "";
                        }
                        loc3 = "<font color=\'#ffff00\'>" + loc9.name + loc11 + loc9.property + "</font>" + loc10;
                        if (this._propContainer.getTextByIndex(loc2) == null) 
                        {
                            this._propContainer.addNewText(150, loc3, 13, 16776960);
                        }
                        this._propContainer.setText(loc2, loc3, true);
                        ++loc2;
                    }
                }
                ++loc6;
            }
            loc6 = loc2;
            while (loc6 < this._propContainer.numChildren) 
            {
                this._propContainer.setText(loc6, "", false);
                ++loc6;
            }
            this._splitLine.y = this._propContainer.y + 18 * loc2 + 5;
            this._lbGet.y = this._splitLine.y + 5;
            this._txtMaxScore.y = this._lbGet.y + this._lbGet.height + 5;
            this._txtMaxLevel.y = this._txtMaxScore.y + 15;
            this._txtStatus.y = this._txtMaxLevel.y + 22;
            this._propContainer.resetPosition2();
            loc3 = Language.getString(80342);
            loc1 = MagicWeaponConfig.instance.getConfigByKeys(["color", "type"], [this._data.color, 4]);
            var loc7=20;
            if (!(loc1 == null) && loc1[0] is TAmuletConfig) 
            {
                loc7 = TAmuletConfig(loc1[0]).level;
            }
            if (this._data.magicWeaponLv < loc7) 
            {
                loc3 = Language.getString(80341) + ", " + loc3;
            }
            this._txtStatus.text = loc3;
            this._txtMaxScore.text = Language.getStringByParam(80361, ItemsUtil.getColorName(this._data.color), int(ItemsUtil.MagicWeaponScoreTimes[this._data.color] * 100).toString());
            this._txtMaxLevel.text = Language.getStringByParam(80345, loc7);
            return;
        }

        /* internal  */set isNoPropertyWeapon(arg1: Boolean)
        {
            if (arg1) 
            {
                if (this._zeroWeaponTxt == null) 
                {
                    this._zeroWeaponTxt = ObjCreate.createGTextField(Language.getString(27633), 118, 20, 88, 50, null, GlobalStyle.setTextFormatAlign(GlobalStyle.setTextFormatLeading(GlobalStyle.textFormatRed, 4), TextAlign.CENTER), true);
                    this._zeroWeaponTxt.wordWrap = true;
                    this._zeroWeaponTxt.multiline = true;
                }
                this._txtName.htmlText = this._data.htmlName + HTMLUtil.addColor("[" + Language.getString(27629) + "]", this._data.itemInfo.colorStr);
                this._txtBind.text = "";
                this.addChildAt(this._zeroWeaponTxt, this.getChildIndex(this._txtBind));
            }
            else 
            {
                DisplayUtil.removeMe(this._zeroWeaponTxt);
            }
            return;
        }

        /* internal  */setNotIdentifyMode(): void
        {
            this.setAllVisibles(true);
            if (this._data.isFaultMagicWeapon || MagicWeaponUtil.isShowMask(this._data)) 
            {
                this._lbCheck1.visible = false;
                this._lbCheck2.visible = false;
                this._lbCheck3.visible = false;
                this._lbScore.visible = false;
                this._askContainer.visible = false;
                this._faultTxt1.text = "[异常]";
                this._faultTxt2.text = "该法宝存在异常，系统于9月14号\n已补发新的法宝；\n此法宝将于下次更新时自动销毁；";
            }
            this._lbAttack.textColor = 16769795;
            this._lbShouHu.textColor = 16769795;
            this._splitLine.y = 252;
            this._lbGet.y = 257;
            this._txtStatus.y = this._lbGet.y + this._lbGet.height + 5;
            this._txtStatus.text = Language.getString(80346);
            return;
        }

        /* internal  */initView(): void
        {
            var loc1=null;
            this._txtName = this.createGTextField("", 0, 0, 200, 20, this);
            loc1 = this._txtName.defaultTextFormat;
            loc1.size = 15;
            loc1.bold = true;
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._txtName.defaultTextFormat = loc1;
            this._txtBind = this.createGTextField("", 117, 30, 78, 20, this);
            this._lbScore = this.createGTextField(Language.getString(80344), 117, 62, 78, 20, this);
            this._txtScore = this.createGTextField("", 0, 53, 160, 55, this);
            loc1 = this._txtScore.defaultTextFormat;
            loc1.size = 44;
            loc1.font = FontUtil.xingkaiName;
            loc1.align = flash.text.TextFormatAlign.RIGHT;
            this._txtScore.defaultTextFormat = loc1;
            this._lbCheck1 = this.createGTextField("", 117, 81, 81, 20, this);
            this._lbCheck1.htmlText = Language.getString(80338);
            this._lbCheck2 = this.createGTextField("", 117, 130, 81, 20, this);
            this._lbCheck2.htmlText = Language.getString(80338);
            this._lbCheck3 = this.createGTextField("", 117, 233, 81, 20, this);
            this._lbCheck3.htmlText = Language.getString(80338);
            this.initAskContainer();
            this._score = ObjCreate.createBitmap(ImagesConst.ScoreBig, 160, 56, this);
            this._icon = new SWFPlayer();
            this._icon.move(60, 100);
            this._icon.timeRate = 6;
            this.addChild(this._icon);
            this._lbAttack = this.createGTextField(Language.getString(80339), 8, 106, 78, 20, this);
            this._txtAttack = this.createGTextField("", 33, 127, 150, 20, this);
            this._lbShouHu = this.createGTextField(Language.getString(80340), 8, 155, 78, 20, this);
            this._propContainer = new AutoLayoutTextContainer();
            this._propContainer.x = 33;
            this._propContainer.y = 176;
            this._propContainer.verticalGap = -2;
            this.addChild(this._propContainer);
            ObjCreate.createBg(18, 100, 166, 2, this, ImagesConst.SplitLine);
            ObjCreate.createBg(18, 149, 166, 2, this, ImagesConst.SplitLine);
            this._splitLine = ObjCreate.createBg(18, 252, 166, 2, this, ImagesConst.SplitLine);
            this._lbGet = ObjCreate.createAutoSizeGTextFiled("", 8, 257, 193, this);
            this._txtMaxScore = this.createGTextField("", 8, 274, 180, 20, this);
            this._txtMaxLevel = this.createGTextField("", 8, 291, 180, 20, this);
            this._txtStatus = this.createGTextField("", 8, 308, 180, 20, this);
            loc1 = this._txtStatus.defaultTextFormat;
            loc1.color = 51426;
            this._txtStatus.defaultTextFormat = loc1;
            this._faultTxt1 = this.createGTextField("", 0, 0, 78, 20, this);
            this._faultTxt2 = this.createGTextField("", 5, 186, 180, 60, this);
            this._faultTxt2.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._faultTxt1.textColor = 16711680;
            this._faultTxt2.textColor = 16711680;
            return;
        }

        /* internal  */initAskContainer(): void
        {
            var loc2=null;
            if (this._askContainer == null) 
            {
                this._askContainer = new Object /* flash.display.Sprite */();
                this.addChild(this._askContainer);
            }
            var loc1=0;
            while (loc1 < MagicWeaponToolTip.askLabelPlaces.length) 
            {
                loc2 = MagicWeaponToolTip.askLabelPlaces[loc1];
                ObjCreate.createBitmap(ImagesConst.AskLabelSmall, loc2.x, loc2.y, this._askContainer);
                ++loc1;
            }
            return;
        }

        /* internal  */getQualityName(): string
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc1="";
            if (this._data == null) 
            {
                return "";
            }
            if (this._data.itemExInfo) 
            {
                if (this._data.itemInfo.item.color > 2) 
                {
                    loc3 = GameDefConfig.instance.getEPrefixx(this._data.itemExInfo.prefix, this._data.type);
                    if (loc3) 
                    {
                        loc2 = loc3.name;
                    }
                    loc4 = ColorConfig.instance.getItemColorString(this._data.itemInfo.item.color);
                    loc1 = HTMLUtil.addColor("[" + loc2 + "]", loc4);
                }
            }
            return loc1;
        }

        /* internal  */createGTextField(arg1: string, arg2: int=0, arg3: int=0, arg4: int=220, arg5: int=20, arg6: Object /* flash.display.DisplayObjectContainer */=null, arg7: Object /* flash.text.TextFormat */=null, arg8: Boolean=true): GTextFiled
        {
            var loc1;
            var loc2;
            (loc2 = (loc1 = ObjCreate.createGTextField(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)).defaultTextFormat).size = 13;
            loc1.defaultTextFormat = loc2;
            return loc1;
        }

        /* internal */ static /* const */askLabelPlaces: Array<any>=[new Object /* flash.geom.Point */(170, 61), new Object /* flash.geom.Point */(85, 122), new Object /* flash.geom.Point */(98, 122), new Object /* flash.geom.Point */(111, 122), new Object /* flash.geom.Point */(85, 167), new Object /* flash.geom.Point */(98, 167), new Object /* flash.geom.Point */(111, 167), new Object /* flash.geom.Point */(85, 192), new Object /* flash.geom.Point */(98, 192), new Object /* flash.geom.Point */(111, 192), new Object /* flash.geom.Point */(85, 214), new Object /* flash.geom.Point */(98, 214), new Object /* flash.geom.Point */(111, 214)];

        /* internal */ /* var */_txtStatus: GTextFiled;

        /* internal */ /* var */_txtMaxScore: GTextFiled;

        /* internal */ /* var */_txtMaxLevel: GTextFiled;

        /* internal */ /* var */_faultTxt1: GTextFiled;

        /* internal */ /* var */_faultTxt2: GTextFiled;

        /* internal */ /* var */_askContainer: Object /* flash.display.Sprite */;

        /* internal */ /* var */_propContainer: AutoLayoutTextContainer;

        /* internal */ /* var */_splitLine: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_equippedBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpUpArrow: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_txtUpValue: GTextFiled;

        /* internal */ /* var */_data: ItemData;

        /* internal */ /* var */_txtName: GTextFiled;

        /* internal */ /* var */_icon: SWFPlayer;

        /* internal */ /* var */_score: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_txtBind: GTextFiled;

        /* internal */ /* var */_lbScore: GTextFiled;

        /* internal */ /* var */_txtScore: GTextFiled;

        /* internal */ /* var */_lbCheck1: GTextFiled;

        /* internal */ /* var */_lbAttack: GTextFiled;

        /* internal */ /* var */_zeroWeaponTxt: GTextFiled;

        /* internal */ /* var */_txtAttack: GTextFiled;

        /* internal */ /* var */_lbCheck2: GTextFiled;

        /* internal */ /* var */_lbShouHu: GTextFiled;

        /* internal */ /* var */_lbCheck3: GTextFiled;

        /* internal */ /* var */_lbGet: GTextFiled;
    }
